#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
char* longestPalindrome(char* s)
{
    int len = 0;
    char* tmp = s;
    while (*tmp)
    {
        tmp++;
        len++;
    }
    if (len == 1)
    {
        char* str1 = malloc(sizeof(char) + 1);
        *str1 = *s;
        *(str1 + 1) = 0;
        return str1;
    }
    else
    {
        int i = 0;
        int count = 0;
        int length = 0;
        char* loc = NULL;
        for (i = 0; i < len; i++)
        {
            if (s[i] == s[i + 1])
            {
                char* left = s + i;
                char* right = s + i + 1;
                while (left >= s && right <= s + len - 1 && *left == *right)
                {
                    count++;
                    left--;
                    right++;
                }
                if (count * 2 > length)
                {
                    length = 2 * count;
                    loc = left + 1;
                }
                count = 0;
            }
            if (i >= 1 && s[i - 1] == s[i + 1])
            {
                char* left0 = s + i - 1;
                char* right0 = s + i + 1;
                while (left0 >= s && right0 <= s + len - 1 && *left0 == *right0)
                {
                    count++;
                    left0--;
                    right0++;
                }
                if (count * 2 + 1 > length)
                {
                    length = 2 * count + 1;
                    loc = left0 + 1;
                }
                count = 0;
            }

        }
        if (length)
        {
            char* str2 = malloc(sizeof(char) * length + 1);
            for (i = 0; i < length; i++)
            {
                str2[i] = *loc;
                loc++;
            }
            str2[i] = 0;
            return str2;
        }
        else
        {
            char* str3 = malloc(sizeof(char) + 1);
            *str3 = *s;
            *(str3 + 1) = 0;
            return str3;
        }

    }

}
int main()
{
    char st[1000] = "ccc";
    printf("%s",longestPalindrome(st));
    return 0;
}